package cn.edu.tju.elm.repository;

import cn.edu.tju.elm.model.entity.Food;
import cn.edu.tju.elm.model.entity.OrderDetailet;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface OrderDetailetRepository extends JpaRepository<OrderDetailet,Long> {
    // SQL: SELECT DISTINCT od.food_id FROM OrderDetailet od WHERE od.order_id = :orderId
    @Query("SELECT DISTINCT od.food FROM OrderDetailet od WHERE od.order.id = :orderId")
    List<Food> findFoodsByOrderId(@Param("orderId") Long orderId);
}
